/*
 * File Name：CheckWorklvAdapter.java
 * Copyright：Copyright 2008-2015 CiWong.Inc. All Rights Reserved.
 * Description： CheckWorklvAdapter.java
 * Modify By：pla-gysu
 * Modify Date：2015年1月13日
 * Modify Type：Add
 * Modify by Young
 * Modify Date;2016/07/16
 * Modify Type :add
 */
package com.ciwong.epaper.modules.epaper.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.bean.SwitchQuestionBean;

import java.util.List;

/**
 * 选择题目适配器
 *
 * @author pla-gysu
 * @version ciwong v.1.0 2015年1月27日
 * @since ciwong v.1.0
 */
public class SelectQuestionAdapter extends BaseAdapter {

	private Activity activity;

	private List<SwitchQuestionBean> isDoRecords;
	private static final String TAG = "SelectQuestionAdapter";
	public SelectQuestionAdapter(Activity activity, List<SwitchQuestionBean> isDoRecords) {
		this.activity = activity;
		this.isDoRecords = isDoRecords;
	}






	private static class ViewHolder {
		TextView quesNo;// 题号

		View           arrowView;// 箭头
		Button         mButton;
		RelativeLayout mItemContainer;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;

		if (convertView == null ) {
			holder = new ViewHolder();
			convertView = View.inflate(activity, R.layout.item_select_question,
					null);
			holder.quesNo = (TextView) convertView
					.findViewById(R.id.item_question_title);
			holder.arrowView = convertView.findViewById(R.id.item_arrow);
			holder.mButton = convertView.findViewById(R.id.submit_btn_look_result);
			holder.mItemContainer = convertView.findViewById(R.id.rl_item);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if(isDoRecords.get(position).isButton()){
			holder.mButton.setVisibility(View.VISIBLE);
			holder.mItemContainer.setVisibility(View.GONE);
		}else{
			holder.mItemContainer.setVisibility(View.VISIBLE);
			holder.mButton.setVisibility(View.GONE);
			boolean isDone = isDoRecords.get(position).isComplected();

			holder.quesNo.setText(activity.getString(R.string.big_question_title,
					position + 1 + ""));

			holder.quesNo.setTextColor(activity.getResources().getColor(isDone
					? R.color.select_question_gray : R.color.default_text_color));

			holder.arrowView.setVisibility(isDone ? View.GONE : View.VISIBLE);

			convertView.setBackgroundResource(
					isDone ? 0 : R.drawable.list_item_bg_selector);
		}

		return convertView;
	}



	@Override
	public int getCount() {
		if (null != isDoRecords) {
			return isDoRecords.size();
		} else {
			return 0;
		}

	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
